<?
$start="../";
$dirs=array();
$url_base = ereg_replace("websitebackup.php", '', "$_SERVER[PATH_TRANSLATED]");
$url_base=str_replace("\\\\","/",$url_base);
$dirs[]="--Server Root--";
if ($handle = opendir($start)) {
    while (false !== ($file = readdir($handle))) { 
        if ($file != "." && $file != ".." && is_dir($start.$file)) { 
              $dirs[]=$start.$file;
        } 
    }
    closedir($handle); 
    
}

?>

<HTML>
<HEAD>
<TITLE>PHP Website Backup Helper :: Main</TITLE>
<STYLE type="text/css">
BODY {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10pt;
}

.textbox {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 8pt;
	background-color: #BDD7F7;
	border: 1px solid #000000;
	color: #000000;
}
</STYLE>
</HEAD>
<BODY BGCOLOR="#F4F4F4">
<CENTER>
  <TABLE WIDTH="80%" bgcolor="#8BA5C5">
    <TR>
      <TD bgcolor="#BDD7F7"><h3><font color="#6699CC">PHP <font color="#FF9900">Website</font> Backup :: Help</font></h3></TD>
    </TR>
    <TR> 
      <TD valign="top"> 
        <ul>
          <li> 
            <div align="left"><font color="#66FFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">MySQL 
              PHP Backup has been tested on Linux 2.4.18 running PHP 4.2+ .  
              USE AT YOUR OWN RISK. <br>
              For zipped download PHP must be compiled with GZIP.<br>
              Pear.php must be available on the server.<br>
              </font></div>
          </li>
          <li> 
            <div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
              <B>Step Two:</B> You must do a backup <font color="#FF0000">before</font> 
              any other request below. Default values have been placed in the 
              below form, but you need to ensure their accuracy for this script 
              to process your requests. All directories are listed below.</font></div>
          </li>
          <li> 
            <div align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
              </font><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">This 
              script will generate a backup directory that will contain the backup 
              file using the form below. </font><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><br>
              <font color="#FFFFFF">Creating a backup might overwrite any other 
              backup made from this script. </font></font></div>
          </li>
          <li> 
            <div align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif" color="#FFFFFF">For safety 
            download the zip off the server.
            Do NOT rely on a backup on the server. A harddisk might crash.</font></div>
          </li>
          <li> 
            <div align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif" color="#FFFFFF">Doing 
              a delete will delete from server any backup files that this program 
              generates.</font> </div>
          </li>
          <li><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">After 
            downloading the backup, delete it from the server.</font></li>
          <li><font color="#990000" size="1" face="Verdana, Arial, Helvetica, sans-serif">Php 
            might time out, this script sets max-timeout to 0 (never timeout). 
          </font></li>
            
          <li><?
          if (get_extension_funcs('zlib'))  {
             echo "<font color='green'>Zlib has been found on the server." ;
          } else {
             echo "<font color='red'>Zlib is NOT installed on the server !";
          } ?>
          </font></li>      
        </ul>
        <font color="#66FFFF" face="Arial, Helvetica, sans-serif" style="font-size:6Pt">
        Php Website Backup Version 1.1 &copy; 2004 by <a href="http://www.absoft-my.com" target="_blank">AB 
        Webservices</a></font> </TD>
    </TR>
  </TABLE>



 
<FORM NAME="dobackup" METHOD="post" ACTION="backup.php"> 
<table width="80%" border="0" cellspacing=0 cellpadding=0 bgcolor="#8BA5C5" align="center">
  <tr align=center>
    <td colspan=5 >
    <TABLE WIDTH="500" BORDER="0" CELLPADDING="5" CELLSPACING="1" bgcolor="#8BA5C5">
      <TR>
        <TD colspan="2" NOWRAP><div align="center"><strong>CREATE A BACKUP</strong></div></TD>
      </TR>
      <TR> 
      <TR> 
        <TD NOWRAP WIDTH="200"> <FONT SIZE="2" FACE="verdana,sans-serif">Full 
          path to this script:</FONT><br><br></TD>
        <TD NOWRAP WIDTH="300"> <INPUT NAME="path" TYPE="text" class="textbox" VALUE="<?=$url_base;?>" SIZE="37" MAXLENGTH="100"><br><br> 
        </TD>
      </TR>

    </table>
    </td>
  </tr>  
    <td width="30%"></td>
    <td width="40%"><FONT SIZE="1" FACE="verdana,sans-serif"><b>DIRECTORY</b></font></td>
    <td width="5%" align="left"><FONT SIZE="1" FACE="verdana,sans-serif"><b>Select</b></font></td>
    <td width="25%"></td>
  </tr>
  <? 
     sort($dirs,SORT_STRING);
     reset($dirs);

     $d=0;
     for ($c=0;$c<count($dirs);$c++) {
        if ($d==1) {
           $bgc='#BDD7F7';
           $d=0;
        } else {
           $bgc='#B6D2F2';
           $d=1;
        }   
        echo "<tr><td></td><td bgcolor=".$bgc."><FONT SIZE='1' FACE='verdana,sans-serif'>&nbsp;&nbsp;".str_replace("../","",$dirs[$c])."</td>";
        echo "<td align='left' bgcolor=".$bgc."><input type='checkbox' name='select".$c."'>";
        echo "<input type='hidden' name='dirs".$c."' value='". $dirs[$c]."' ></td><td></td></tr>";
     }
  $backupnm="website_".date("d-m-Y_")."TIME.tar.gz";   
  echo "<tr><td></td><td colspan=3>
        <input type='radio' name='chg' onclick='for(i=0;i<$c;i++){document.getElementById(\"select\"+i).checked=true;}'><FONT SIZE='1' FACE='verdana,sans-serif'> Check All  &nbsp;&nbsp;</font>
        <input type='radio' name='chg' onclick='for(i=0;i<$c;i++){document.getElementById(\"select\"+i).checked=false;}'><FONT SIZE='1' FACE='verdana,sans-serif'> Uncheck All &nbsp;&nbsp;</font>
        <br><br></td></tr>";
  
  echo "<tr><td colspan=4  align='center'>
        <font color='#990000' size='2'><strong>Backup File Name: $backupnm <br>
        </strong><font size=1>where time=start time of backup</font></font>
        </td></tr><tr><td align='center' colspan='4'><br>
        <input type='submit' name='send2' value ='Backup' class='textbox'><br>
        This backup may take a long time depending on the number of files !
        <br><br>
        </td></tr>
     </table>
   </form>";
?>
<FORM NAME="dodelete" METHOD="post" ACTION="delete.php">
<CENTER>
      <TABLE WIDTH="500" HEIGHT="75" BORDER="0" CELLPADDING="5" CELLSPACING="1" bgcolor="#8BA5C5">
        <tr>
          <td><div align="center"><B>DELETE BACKUP</B></div></td>
        </tr>
        <tr> 
          <td><CENTER>
              <INPUT TYPE="hidden" NAME="path" value=<?=$url_base;?>>
              <INPUT NAME="send4" TYPE="submit" class="textbox" VALUE="Delete">
            </CENTER></td>
        </tr>
      </table>
      
    </CENTER>
</FORM>

<FORM NAME="dodownload" METHOD="post" ACTION="download.php">
<CENTER>
      <TABLE WIDTH="500" HEIGHT="75" BORDER="0" CELLPADDING="5" CELLSPACING="1" bgcolor="#8BA5C5">
        <tr> 
          <td><div align="center"><B>DOWNLOAD BACKUP</B></div></td>
        </tr>
        <tr> 
          <td valign="top" align="center"> 
          <?
           $farr=array();
           if (file_exists($url_base."dump/")) {
              $dir= opendir($url_base."dump/"); 
              $fl = readdir($dir);
              while ($fl = readdir ($dir)) { 
                 if ($fl != "." && $fl != ".." &&  (eregi("\.gz",$fl))){ 
                    $farr[]=$fl;
                 }
              } 
              closedir($dir); 
           }
           if (empty($farr)) $farr[0]="No backup found"; 
          ?>              
             <table width="365" align="center">
                <tr> 
                  <td align="center"><font size="1" face="Arial, Helvetica, sans-serif"> 
                      File to download:  
                      <input name="zipname" type="hidden" value="<?=$farr[0];?>" >
                      <?=$farr[0];?></font></td>
                </tr>
             </table>
           </td>
        </tr>
        <tr> 
          <td><CENTER>
              <INPUT type="hidden" name="path" value="<?=$url_base;?>">
              <INPUT NAME="send4" TYPE="submit" class="textbox" VALUE="Go">
            </CENTER></td>
        </tr>
      </table>
      
    </CENTER>
  </FORM>
